//
//  CustomTool.m
//  KeyBoard
//
//  Created by MyMac on 15/10/23.
//  Copyright © 2015年 tongfang. All rights reserved.
//

#import "CustomTool.h"

@interface CustomTool()
@property(nonatomic,copy)KeyBoardBlock keyBoardHideBlock;
@property(nonatomic,copy)KeyBoardBlock keyBoardShowBlock;
@property(nonatomic,strong)NSMutableDictionary*keyBoardShowBlockDic;
@property(nonatomic,strong)NSMutableDictionary*keyBoardHideBlockDic;
@end
@implementation CustomTool

+(instancetype)shareCustomTool{

    static CustomTool*tool;
    
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        tool=[[CustomTool     alloc]init];
    });
    return tool;

}
-(NSMutableDictionary*)keyBoardHideBlockDic{
    if (!_keyBoardHideBlockDic) {
        _keyBoardHideBlockDic=[NSMutableDictionary dictionary];
    }
    return _keyBoardHideBlockDic;
}
-(NSMutableDictionary*)keyBoardShowBlockDic{
    if (!_keyBoardShowBlockDic) {
        _keyBoardShowBlockDic=[[NSMutableDictionary alloc]init];
    }
    return _keyBoardShowBlockDic;
}
+(void)keyBoardAddObserver:(id)observer showBlcok:(void(^)(CGRect keyBoardBounds,CGFloat animationDuration,NSDictionary*userIfon))showBlock hideBlock:(void(^)(CGRect keyBoardBounds,CGFloat animationDuration,NSDictionary*userIfon))hideBlock{
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyBoardWillDisplay:) name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyBoardWillHide:) name:UIKeyboardWillHideNotification object: nil];
}
+(void)keyBoardWillDisplay:(NSNotification*)noti{



}
+(void)keyBoardWillHide:(void(^)(CGRect keyBoardBounds,CGFloat animationDuration,NSDictionary*userIfon))hideBlock{
   hideBlock(CGRectZero,0,nil);


}
-(void)toolKeyBoardShowAndHideOperatuonWithshowOPeration:(KeyBoardBlock)showBlock hideOPeration:(KeyBoardBlock)hideBlock blockLifeObjc:(id)objc{
    CustomTool*tool=[CustomTool shareCustomTool];
    static int i=1;
    i++;
    
    [self.keyBoardShowBlockDic setObject:showBlock forKey:[NSString stringWithFormat:@"%ld",(long)i]];
    static int j=0;
    j++;
    
    [self.keyBoardHideBlockDic setObject:hideBlock forKey:[NSString stringWithFormat:@"%ld",(long)j]];
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        [[NSNotificationCenter defaultCenter] addObserver:tool selector:@selector(keyBoardWillDisplay:) name:UIKeyboardWillShowNotification object:nil];
        [[NSNotificationCenter defaultCenter]addObserver:tool selector:@selector(keyBoardWillHide:) name:UIKeyboardWillHideNotification object:nil];

    });
   

    
 

}
//-(void)keyBoardWillDisplay:(NSNotification*)noti{
//    CustomTool*tool=[CustomTool shareCustomTool];
//    NSDictionary*notifiDic=noti.userInfo;
//    CGRect keyBoardBounds=  [notifiDic[UIKeyboardFrameEndUserInfoKey] CGRectValue];
//    double animationDuration=[notifiDic[UIKeyboardAnimationDurationUserInfoKey] doubleValue];
//
//
//        for (NSUInteger i=0; i<tool.keyBoardShowBlockArray.count; i++) {
//            NSValue*value=tool.keyBoardShowBlockArray[i];
//
//                KeyBoardBlock showBlock=[value pointerValue];
//            showBlock(keyBoardBounds,animationDuration,notifiDic);
//        }
//}
//-(void)keyBoardWillHide:(NSNotification*)noti{
//    CustomTool*tool=[CustomTool shareCustomTool];
//    NSDictionary*notifiDic=noti.userInfo;
//      CGRect keyBoardBounds=  [notifiDic[UIKeyboardFrameEndUserInfoKey] CGRectValue];
//    double animationDuration=[notifiDic[UIKeyboardAnimationDurationUserInfoKey] doubleValue];
//
//
//for (NSUInteger i=0; i<tool.keyBoardHideBlockArray.count; i++) {
//            KeyBoardBlock hideBlock=(KeyBoardBlock)tool.keyBoardHideBlockArray[i];
//            hideBlock(keyBoardBounds,animationDuration,notifiDic);
//      }
//
//}
-(void)dealloc{
   [[NSNotificationCenter defaultCenter]removeObserver:self name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter]removeObserver:self name:UIKeyboardWillHideNotification object:nil];
}
@end
